<template>
	<view>
		<scroll-view scroll-y class="page">
			<cu-custom bgColor="bg-gradual-pink" :cusBack="cusBack" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">
					<text v-if="roleCode == 'ywyjs'">我的教练</text>
					<text v-else-if="roleCode == 'jiaolian'">我的学员</text>
				</block>
			</cu-custom>
			<view class="table">
				<view class="header th">
					<view class="name">用户姓名</view>
					<view class="avatar">头像</view>
					<view class="sex">性别</view>
					<view class="phone">手机号</view>
					<view class="viplevel">会员等级</view>
				</view>
				<view class="body">
					<view v-for="student in studentList" class="th">
						<view class="name">{{student.realname}}</view>
						<view class="avatar">
							<view class="cu-avatar round lg" v-if="student.avatar"
								:style="[{ backgroundImage:'url(' + student.avatar + ')' }]"></view>
						</view>
						<view class="sex">{{student.sex_dictText}}</view>
						<view class="phone">{{student.phone}}</view>
						<view class="viplevel">
							<view>{{student.vipLevel}}</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getFileAccessHttpUrl
	} from '@/api/api.js';
	export default {
		data() {
			return {
				studentList: [],
				roleUrl: 'sys/user/queryUserRole',
				roleListUrl: 'sys/role/queryallNoByTenant',
				roleCode: '',
			};
		},
		onLoad() {
			this.getStudentList()
			this.getRole()
		},
		methods: {
			cusBack() {
        this.$Router.back();
				//this.$Router.push('/pages/user/people')
			},
			getRole() {
				const userId = this.$store.getters.userid
				this.$http.get(this.roleUrl, {
					params: {
						userid: userId
					}
				}).then(outRes => {
					console.log("postUrl", outRes)
					if (outRes.data.success) {
						this.$http.get(this.roleListUrl).then(res => {
							console.log("postUrl", res)
							if (res.data.success) {
								let {
									result
								} = res.data;
								this.roleCode = (result.find(f => f.id === outRes.data.result[0]) || {})
									.roleCode;
							}
						}).catch(err => {
							console.log(err);
						});
					}
				}).catch(err => {
					console.log(err);
				});
			},
			getStudentList() {
				console.log(this.$store)
				const bingCode = this.$store.getters.userInfo.inviteCode
				const url =
					'https://www.jiakaogo.cn/jeecg-boot/sys/user/listAll?column=createTime&order=desc&pageNo=1&pageSize=100&bingCode=' +
					bingCode + '&_t=1710520876985'
				this.$http.get(url).then(res => {
					this.studentList = res?.data?.result?.records || []
					this.studentList.forEach(item => {
						if (item.avatar) item.avatar = getFileAccessHttpUrl(item.avatar)
					})
					console.log(this.studentList)
				})
			},
		}
	}
</script>

<style>
	.page {
		height: 100Vh;
		width: 100vw;
	}

	.page.show {
		overflow: hidden;
	}

	.table {
		height: calc(100vh - 60px);
	}

	.table .th {
		height: 40px;
		line-height: 40px;
		text-align: center;
		display: flex;
		border-bottom: 1px solid #333;
	}

	.table .body {
		height: calc(100% - 40px);
		line-height: 40px;
		text-align: center;
		overflow-y: auto;
	}

	.table .name {
		width: 20%;
	}

	.table .avatar {
		width: 20%;
	}

	.table .sex {
		width: 10%;
	}

	.table .phone {
		width: 30%;
	}

	.table .viplevel {
		width: 20%;
		overflow: auto;
	}

	.table .viplevel view {
		width: max-content;
	}
</style>